<template>
  <div>
    <div class="header">
      <el-button type="primary" size="mini" @click="addstudent">新增其他费</el-button>
    </div>
    <div style="margin-top:15px">
      <el-table v-loading="tableLoading" class="gl_table_noBorder" size="mini" :data="tableData">
        <el-table-column label="序号" type="index" align="center" width="55" />
        <el-table-column label="收费名项" prop="name" />
        <el-table-column label="费用">
          <template slot-scope="{row}">
            {{ (row.amount/100).toFixed(2) }}
          </template>
        </el-table-column>
        <el-table-column label="创建时间">
          <template slot-scope="{ row }">
            <span v-if="row.creationTime">
              {{ row.creationTime | FormatDate('yyyy-MM-dd HH:mm:ss') }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="创建人" align="center" prop="creatorName" />
        <el-table-column label="状态" align="center">
          <template slot-scope="{ row }">
            <span>
              {{ row.isEnabled ? '启用': '禁用' }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="考试必选" align="center">
          <template slot-scope="{ row }">
            <span>
              {{ row.isExamRequired ? '是': '否' }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="{ row }">
            <el-button v-if="row.isEnabled" size="mini" style="color:red" type="text" @click="pass(row.id)">禁用</el-button>
            <el-button v-else size="mini" type="text" @click="enable(row.id)">启用</el-button>
            <el-button size="mini" type="text" @click="toOrganization(row)">编辑</el-button>
            <el-button size="mini" type="text" style="color:red" @click="close(row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <AddFee ref="AddFee" />
    <el-row class="gl_pt_15" style="text-align: right;">
      <el-pagination
        :current-page="Api_GET_ClubFeeQO.Page"
        :page-size="Api_GET_ClubFeeQO.MaxResultCount"
        :total="totalPage"
        layout="total,sizes,prev,pager,next,jumper"
        :page-sizes="[10, 20, 30, 40]"
        @size-change="sizeChange"
        @current-change="pageIndexChange"
      />
    </el-row>
  </div>
</template>

<script>
import { mapState, mapActions } from 'vuex';
import { api_GET_ClubFee, api_POST_ClubFeeIdDisable, api_POST_ClubFeeIdEnable, api_DELETE_ClubFeeId } from '@/extend/api/hallswaggerApi/app.js';
import { Api_GET_ClubFeeQO } from '@/lib/form/hall/swaggerForm';
import AddFee from './addFee.vue';
export default {
  components: {
    AddFee
  },
  data() {
    return {
      tableLoading: false,
      tableData: [],
      IsEnabled: '',
      totalPage: 0,

      Api_GET_ClubFeeQO: new Api_GET_ClubFeeQO() // 分道馆商城数据
    };
  },
  computed: {
    ...mapState({
      dict: state => state.dict.dict,
      user: state => state.user.currentOU
    })
  },
  created() {
    this.getDict();
    this.gettablelist();
  },
  methods: {
    ...mapActions({ getDict: 'dict/getDict', getDictByType: 'dict/getDictByType' }),
    // 获取会员费列表
    gettablelist(page) {
      this.tableLoading = true;
      this.Api_GET_ClubFeeQO.IsEnabled = ''; // type: boolean
      this.Api_GET_ClubFeeQO.IsExamRequired = ''; // type: boolean
      this.Api_GET_ClubFeeQO.FeeTypeCode = 'Other'; // type: string
      this.Api_GET_ClubFeeQO.OrganizationUnitId = this.user;
      this.Api_GET_ClubFeeQO.Sorting = 'creationTime DESC';
      this.Api_GET_ClubFeeQO.Page = page || 1;
      this.Api_GET_ClubFeeQO.SkipCount = (this.Api_GET_ClubFeeQO.Page - 1) * this.Api_GET_ClubFeeQO.MaxResultCount;
      console.log(this.Api_GET_ClubFeeQO);
      api_GET_ClubFee(this.Api_GET_ClubFeeQO).then(res => {
        this.totalPage = res.totalCount;
        this.tableData = res.items;
        this.tableLoading = false;
      }, error => {
        this.tableLoading = false;
        const _msg = error.error.message || error.message;
        this.$message({ type: 'error', message: _msg });
      });
    },
    addstudent() {
      this.$refs.AddFee.title = '新增其他费';
      this.$refs.AddFee.formdata.feeTypeCode = 'Other';
      this.$refs.AddFee.dialogVisible = true;
    },
    // 分页按钮
    sizeChange(MaxResultCount) {
      this.Api_GET_ClubFeeQO.MaxResultCount = MaxResultCount;
      this.gettablelist();
    },
    pageIndexChange(currentPage) {
      this.gettablelist(currentPage);
    },
    // 重置按钮
    reset () {
      this.Api_GET_ClubFeeQO = new Api_GET_ClubFeeQO();
      this.gettablelist();
    },
    // 禁用
    pass(id) {
      this.$confirm(`您确定要禁用吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          api_POST_ClubFeeIdDisable(id).then(res => {
            this.$message({
              message: '禁用成功',
              type: 'success'
            });
            this.gettablelist();
          }, error => {
            const _msg = error.error.message || error.message;
            this.$message({ type: 'error', message: _msg });
          });
        });
    },
    // 启用
    enable(id) {
      this.$confirm(`您确定要启用吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          api_POST_ClubFeeIdEnable(id).then(res => {
            this.$message({
              message: '启用成功',
              type: 'success'
            });
            this.gettablelist();
          }, error => {
            const _msg = error.error.message || error.message;
            this.$message({ type: 'error', message: _msg });
          });
        });
    },
    // 删除按钮
    close(id) {
      this.$confirm(`您确定要删除吗？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          api_DELETE_ClubFeeId(id).then(res => {
            this.$message({
              message: '删除成功',
              type: 'success'
            });
            this.gettablelist();
          }, error => {
            const _msg = error.error.message || error.message;
            this.$message({ type: 'error', message: _msg });
          });
        });
    },
    // 编辑会员费
    toOrganization(row) {
      this.$refs.AddFee.title = '编辑其他费';
      this.$refs.AddFee.id = row.id;
      this.$refs.AddFee.formdata.name = row.name;
      this.$refs.AddFee.formdata.amount = row.amount / 100;
      this.$refs.AddFee.formdata.isEnabled = row.isEnabled;
      this.$refs.AddFee.formdata.isExamRequired = row.isExamRequired;
      this.$refs.AddFee.formdata.feeTypeCode = 'Other';
      console.log(row, this.$refs.AddFee.formdata);
      this.$refs.AddFee.dialogVisible = true;
    }
  }

};
</script>

<style lang="scss" scoped>
</style>
